#include "CVipConfig.h"

int CVipConfig::Init()
{
    _astVipDailyAwardConfigs.m_iUsedCount = MAX_VIP_LEVEL+1;
    _astVipLevelAwardConfigs.m_iUsedCount = MAX_VIP_LEVEL+1;

    for (int i = 0; i < _astVipDailyAwardConfigs.Size(); ++i)
    {
        _astVipDailyAwardConfigs[i].Clear();
    }

    for (int i = 0; i < _astVipLevelAwardConfigs.Size(); ++i)
    {
        _astVipLevelAwardConfigs[i].Clear();
    }

    return 0;
}

int CVipConfig::AddVipLevelAwardConfig(CVipAwardConfigData& stData)
{
    if (!stData.HasConfig())
    {
        return ERROR_VIP_AWARD_ADD_EMPTY_CONFIG;
    }

    int iVipLevel = stData._iVipLevel;
    if( iVipLevel>=_astVipLevelAwardConfigs.GetCount() )
    {
        return ERROR_VIP_AWARD_CONFIG;
    }

    if (_astVipLevelAwardConfigs[iVipLevel].HasConfig())
    {
        //return ERROR_VIP_AWARD_DUPLICATED_CONFIG;
        _astVipLevelAwardConfigs[iVipLevel]._aTAwards.AddOneItem(stData._aTAwards[0]);
    }
    else
    {
        _astVipLevelAwardConfigs[iVipLevel] = stData;
    }

    return 0;
}

int CVipConfig::AddVipDailyAwardConfig( CVipAwardConfigData& stData )
{
    if (!stData.HasConfig())
    {
        return ERROR_VIP_AWARD_ADD_EMPTY_CONFIG;
    }

    int iVipLevel = stData._iVipLevel;
    if( iVipLevel>=_astVipDailyAwardConfigs.GetCount() )
    {
        return ERROR_VIP_AWARD_CONFIG;
    }

    if (_astVipDailyAwardConfigs[iVipLevel].HasConfig())
    {
        //return ERROR_VIP_AWARD_DUPLICATED_CONFIG;
        _astVipDailyAwardConfigs[iVipLevel]._aTAwards.AddOneItem(stData._aTAwards[0]);
    }
    else
    {
        _astVipDailyAwardConfigs[iVipLevel] = stData;
    }

    return 0;
}

int CVipConfig::GetVipLevelAwardConfig(int iVipLevel, CVipAwardConfigData& stData)
{
    if( iVipLevel >= _astVipLevelAwardConfigs.GetCount() )
    {
        return ERROR_VIP_LEVEL_ID;
    }

    if( !_astVipLevelAwardConfigs[iVipLevel]._bHasConfig )
    {
        return ERROR_VIP_LEVEL_ID;
    }

    stData = _astVipLevelAwardConfigs[iVipLevel];

    return 0;
}

int CVipConfig::GetVipDailyAwardConfig(int iVipLevel, CVipAwardConfigData& stData)
{
    if( iVipLevel >= _astVipDailyAwardConfigs.GetCount() )
    {
        return ERROR_VIP_LEVEL_ID;
    }

    if( !_astVipDailyAwardConfigs[iVipLevel]._bHasConfig )
    {
        return ERROR_VIP_LEVEL_ID;
    }

    stData = _astVipDailyAwardConfigs[iVipLevel];

    return 0;
}

int CVipConfig::GetVipPayGoldConfig(int iVipLevel, CVipPayGoldConfig& stData)
{
    if( iVipLevel >= _astVipPayGoldConfigs.GetCount() )
    {
        return ERROR_VIP_LEVEL_ID;
    }

    if( !_astVipDailyAwardConfigs[iVipLevel]._bHasConfig )
    {
        return ERROR_VIP_LEVEL_ID;
    }

    stData = _astVipPayGoldConfigs[iVipLevel];

    return 0;
}

int CVipConfig::AddVipPayGoldConfig( CVipPayGoldConfig& stData )
{
    if (!stData.HasConfig())
    {
        return ERROR_VIP_AWARD_ADD_EMPTY_CONFIG;
    }

    int iVipLevel = stData._iVipLevel;
    if( iVipLevel>=_astVipPayGoldConfigs.GetCount() )
    {
        return ERROR_VIP_LEVEL_ID;
    }

    if (_astVipPayGoldConfigs[iVipLevel].HasConfig())
    {
        return ERROR_VIP_LEVEL_ID;
    }

    _astVipPayGoldConfigs[iVipLevel] = stData;

    return 0;
}

int CVipConfig::GetVipExtNumConfig(int iVipLevel, int iModuleId, CVipExtNumConfig& stData)
{
    for( int i=0; i<_astVipModuleExtConfigs.Size(); ++i )
    {
        if( _astVipModuleExtConfigs[i]._iModuleId==iModuleId && _astVipModuleExtConfigs[i]._iVipLevel==iVipLevel )
        {
            stData = _astVipModuleExtConfigs[i];
            return 0;
        }
    }
    
    return ERROR_VIP_MODULE;
}

int CVipConfig::AddVipExtNumConfig( CVipExtNumConfig& stData )
{
    if (!stData.HasConfig())
    {
        return ERROR_VIP_MODULE;
    }

    if ( _astVipModuleExtConfigs.Size()==_astVipModuleExtConfigs.GetCount() )
    {
        return ERROR_VIP_MODULE_FULL;
    }

    _astVipModuleExtConfigs.AddOneItem( stData );

    return 0;
}

